import time

def HexToStrOnTime(FrameDataHexs):
    FrameData = []
    for item in FrameDataHexs :
       FrameData.append(item)
    textK = []
    for kka in FrameDataHexs :
       textK.append(hex(kka).replace('0x','').zfill(2))
    result = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ': ' + ' '.join(textK)
    return result

def BytesToStrOnTime(DataBuffer):
    KKb = []
    for bc in DataBuffer:
        KKb.append(hex(ord(bc)).replace('0x', '').zfill(2))
        pass
    result = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ': ' + ' '.join(KKb)
    return result


def checkACC(message):
    result = 0
    for value in message:
        result += value
        result &= 0xFF  # 将结果与0xFF进行位运算，取低8位
    return result

def checkACC2Byte(message):
    result = 0
    results = [0x00, 0x00]
    for value in message:
        result += value
    results[0] = (result >> 8) & 0x00FF
    results[1] = result & 0x00FF
    return results

def checkACC1Byte(message):
    Checksum = 0
    for value in message:
        Checksum += value
    Checksum = Checksum & 0X00FF
    return Checksum

def get_s16(val):
    if val < 0x8000:
        return val
    else:
        return (val - 0x10000)

